/*
 * @author: wizardc
 */

using System.Collections.Generic;

namespace DouEditor.ConfigParser
{
    public class ConfigInfo
    {
        public string filePath;
        public string fileName;
        public string sheetName;
        public string sheetDesc;
        
        internal List<Field> fields = new List<Field>();
        internal List<bool> rowComments = new List<bool>();
        
        public int dataCount
        {
            get
            {
                if (fields.Count == 0)
                {
                    return 0;
                }
                return fields[0].dataList.Count;
            }
        }

        public Field GetKey()
        {
            foreach (var info in fields)
            {
                if ((info.field.exportType & FieldExportType.Key) != 0)
                {
                    return info;
                }
            }
            return null;
        }
        
        public List<Field> GetFields(FieldExportType exportType)
        {
            var result = new List<Field>();
            foreach (var info in fields)
            {
                if ((info.field.exportType & exportType) != 0)
                {
                    result.Add(info);
                }
            }
            return result;
        }
    }
    
    public class Field
    {
        public FieldInfo field = new FieldInfo();
        public List<string> dataList = new List<string>();
    }
    
    public class FieldInfo
    {
        public string name;
        public string type;
        public string desc;
        public FieldExportType exportType;
    }
    
    public enum FieldExportType
    {
        Key = 1,
        Client = 1 << 1,
        Server = 1 << 2,
        All = Key | Client | Server
    }
}
